home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2006 September / SAN CD 9-2006 CD-ROM 16.iso / pc / Software / Network Telescope Control / NTC-Setup.Exe / Source / ntc_client_planets.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2006-03-24  |  6.1 KB  |  306 lines

  1. unit ntc_client_planets;
  2. {
  3.     Copyright (C) 2004 - 2006 Andrew Sprott
  4.  
  5.     http://astronomy.crysania.co.uk
  6.     astro@trefach.co.uk
  7.  
  8.     This program is free software; you can redistribute it and/or
  9.     modify it under the terms of the GNU General Public License
  10.     as published by the Free Software Foundation; either version 2
  11.     of the License, or (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. }
  22.  
  23. interface
  24.  
  25. uses
  26.     Windows,
  27.     Messages,
  28.     SysUtils,
  29.     Variants,
  30.     Classes,
  31.     Graphics,
  32.     Controls,
  33.     Forms,
  34.     Dialogs,
  35.     StdCtrls,
  36.     Buttons,
  37.     ExtCtrls,
  38.     inifiles,
  39.  
  40.     ntc_client_form;
  41.  
  42. const
  43.     { 2 hours is a long time :] }
  44.     a_long_time=2*60*60;
  45.  
  46. type
  47.   Tscope_planets = class(TForm)
  48.     planets_panel: TPanel;
  49.     planets_group: TGroupBox;
  50.     mercury_button: TBitBtn;
  51.     venus_button: TBitBtn;
  52.     mars_button: TBitBtn;
  53.     jupiter_button: TBitBtn;
  54.     saturn_button: TBitBtn;
  55.     uranus_button: TBitBtn;
  56.     neptune_button: TBitBtn;
  57.     pluto_button: TBitBtn;
  58.     mercury_led: TEdit;
  59.     venus_led: TEdit;
  60.     mars_led: TEdit;
  61.     jupiter_led: TEdit;
  62.     saturn_led: TEdit;
  63.     uranus_led: TEdit;
  64.     neptune_led: TEdit;
  65.     pluto_led: TEdit;
  66.     merc_ra_edit: TEdit;
  67.     venus_ra_edit: TEdit;
  68.     mars_ra_edit: TEdit;
  69.     jup_ra_edit: TEdit;
  70.     sat_ra_edit: TEdit;
  71.     uranus_ra_edit: TEdit;
  72.     nep_ra_edit: TEdit;
  73.     pluto_ra_edit: TEdit;
  74.     merc_dec_edit: TEdit;
  75.     venus_dec_edit: TEdit;
  76.     mars_dec_edit: TEdit;
  77.     jup_dec_edit: TEdit;
  78.     sat_dec_edit: TEdit;
  79.     uranus_dec_edit: TEdit;
  80.     nep_dec_edit: TEdit;
  81.     pluto_dec_edit: TEdit;
  82.         slew_label: TLabel;
  83.     visible_label: TLabel;
  84.     ra_label: TLabel;
  85.     dec_label: TLabel;
  86.     poll_group: TGroupBox;
  87.     msecs_edit: TEdit;
  88.     refresh_button: TBitBtn;
  89.     Label1: TLabel;
  90.         refresh_check: TCheckBox;
  91.     refresh_timer: TTimer;
  92.     now_button: TBitBtn;
  93.         { form functions }
  94.         procedure formcreate(
  95.             Sender:TObject);
  96.  
  97.         procedure form_close_query(
  98.                     Sender: TObject;
  99.             var CanClose: Boolean);
  100.  
  101.         { configuration }
  102.         procedure load_settings;
  103.  
  104.         procedure save_settings;
  105.  
  106.         { timer poll }
  107.         procedure enable_refresh_timer;
  108.         procedure disable_refresh_timer;
  109.  
  110.         { events }
  111.         procedure FormShow(
  112.             Sender:TObject);
  113.  
  114.         procedure adjust;
  115.  
  116.         procedure check_activate(
  117.             Sender: TObject);
  118.  
  119.         procedure refresh_checkClick(
  120.             Sender: TObject);
  121.  
  122.         procedure now_buttonClick(
  123.             Sender: TObject);
  124.  
  125.     private
  126.         { Private declarations }
  127.     public
  128.         { Public declarations }
  129.         { configuration }
  130.         dimensions:dimensions_record;
  131.  
  132.         { events }
  133.         procedure check_visible_and_show_hide(
  134.             sender:tobject);
  135.  
  136.         procedure hide_form;
  137.         procedure show_form;
  138.     end;
  139.  
  140. var
  141.     scope_planets: Tscope_planets;
  142.  
  143. implementation
  144.  
  145. {$R *.dfm}
  146.  
  147.     { -------------
  148.         form controls
  149.         ------------- }
  150.  
  151. procedure tscope_planets.formcreate(
  152.     Sender:TObject);
  153. begin
  154.     disable_refresh_timer;
  155.     msecs_edit.enabled:=false;
  156.     load_settings;
  157. end;
  158.  
  159. procedure tscope_planets.form_close_query(
  160.             Sender: TObject;
  161.     var CanClose: Boolean);
  162. begin
  163.     canclose:=false;
  164.     visible:=false;
  165.     with dimensions do
  166.         begin
  167.             form_top:=top;
  168.             form_left:=left;
  169.         end;
  170. end;
  171.  
  172.     { -------------
  173.         configuration
  174.         ------------- }
  175.  
  176. procedure tscope_planets.load_settings;
  177. begin
  178.     ini_file:=tinifile.create(application_path+'client.ini');
  179.     with ini_file do
  180.         begin
  181.             { form }
  182.             scope.get_dimensions(scope_planets,@dimensions,'planets',ini_file);
  183.             left:=dimensions.form_left;
  184.             top:=dimensions.form_top;
  185.             visible:=readbool('planets','visible',false);
  186.         end;
  187.     ini_file.free;
  188. end;
  189.  
  190. procedure tscope_planets.save_settings;
  191. begin
  192.     with ini_file do
  193.         begin
  194.             { form }
  195.             scope.find_vdu(scope_planets,@dimensions);
  196.             scope.write_dimensions(@dimensions,left,top,'planets',ini_file);
  197.             writebool('planets','visible',visible);
  198.         end;
  199. end;
  200.  
  201.     { ----------
  202.         timer poll
  203.         ---------- }
  204.  
  205. procedure tscope_planets.enable_refresh_timer;
  206. begin
  207.     with refresh_timer do
  208.         begin
  209.             enabled:=false;
  210.             interval:=strtointdef(msecs_edit.text,0);
  211.             if (interval<=0) or (interval>a_long_time) then
  212.                 interval:=5;
  213.             now_button.caption:='Stop';
  214.             enabled:=true
  215.         end;
  216. end;
  217.  
  218. procedure tscope_planets.disable_refresh_timer;
  219. begin
  220.     refresh_timer.enabled:=false;
  221.     now_button.caption:='Now';
  222. end;
  223.  
  224.     { ------
  225.         events
  226.         ------ }
  227.  
  228. procedure tscope_planets.FormShow(
  229.     Sender:TObject);
  230. begin
  231.     with dimensions do
  232.         begin
  233.             top:=form_top;
  234.             left:=form_left;
  235.         end;
  236. end;
  237.  
  238. procedure tscope_planets.adjust;
  239. begin
  240.     with dimensions do
  241.         begin
  242.             form_top:=trunc(form_top/last_screen_height*current_height);
  243.             form_left:=trunc(form_left/last_screen_width*current_width);
  244.         end;
  245.     if visible then
  246.         show;
  247. end;
  248.  
  249. procedure tscope_planets.check_visible_and_show_hide(
  250.     sender:tobject);
  251. begin
  252.     if visible then
  253.         hide_form
  254.     else
  255.         show_form;
  256.     scope.show_hide(sender,visible);
  257. end;
  258.  
  259. procedure tscope_planets.hide_form;
  260. begin
  261.     with dimensions do
  262.         begin
  263.             form_top:=top;
  264.             form_left:=left;
  265.         end;
  266.     Visible:=false;
  267. end;
  268.  
  269. procedure tscope_planets.show_form;
  270. begin
  271.     Visible:=true;
  272. end;
  273.  
  274. procedure tscope_planets.check_activate(
  275.     Sender: TObject);
  276. begin
  277.     scope.form_activate(scope_planets,@dimensions);
  278. end;
  279.  
  280. procedure Tscope_planets.refresh_checkClick(
  281.     Sender: TObject);
  282. begin
  283.     if refresh_check.Checked then
  284.         begin
  285.             now_button.Enabled:=true;
  286.             msecs_edit.enabled:=true;
  287.         end
  288.     else
  289.         begin
  290.             disable_refresh_timer;
  291.             msecs_edit.enabled:=false;
  292.             now_button.enabled:=false;
  293.         end;
  294. end;
  295.  
  296. procedure Tscope_planets.now_buttonClick(
  297.     Sender: TObject);
  298. begin
  299.     if not refresh_check.Checked or refresh_timer.Enabled then
  300.         disable_refresh_timer
  301.     else
  302.         enable_refresh_timer;
  303. end;
  304.  
  305. end.
  306.